﻿var defServidor = '10.41.117.134';
var defNombre = 'gspSP';
var defPuerto = '8080';
var defProtocolo = 'http';
var nombreEmpresa = 'Grupo Auna';

loadCss();
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    console.log("We got device ready");
    navigator.splashscreen.hide();
}

function loadCss() {
    var osName = Ext.os.name,
    	cssName;
    switch (osName) {
        case 'Android':
            cssName = 'android.css';
            break;
        case 'BlackBerry':
            //if (Ext.os.version.lt('7.0')) {
            //	cssName = 'bb_old.css';
            //}else{
            cssName = 'bb.css';
            //}
            break;
        case 'iOS':
            cssName = 'ios.css';
            break;
        default:
            cssName = 'bb.css';
    }
    var $ = document; // shortcut
    var head = $.getElementsByTagName('head')[0];
    var link = $.createElement('link');
    link.id = 'pOS';
    link.rel = 'stylesheet';
    link.type = 'text/css';
    link.href = 'resources/css/' + cssName;
    head.appendChild(link);
}

function hostValue(ser, nom, pue, pro, formName) {
    var acceso;
    if (nom == 'undefined') { nom = ''; }

    acceso = Ext.ModelMgr.create({
        servidor: ser,
        nombre: nom,
        puerto: pue,
        protocolo: pro,
        hostValue: (nom == "" ? pro + '://' + ser + ':' + pue : pro + '://' + ser + ':' + pue + '/' + nom)
    }, 'accesoModel');
    var sto = Ext.getStore('accesoStore');
    sto.getProxy().clear();
    sto.data.clear();
    sto.sync();
    sto.add(acceso);
    sto.sync();
    if (formName != 'loginForm') {
        formName.animateActiveItem(formName.items.items[0], { type: 'slide', direction: 'left' });
    }
}

function validateUser(storeName) {
    var item = storeName.getAt(0);
    if (!item) {
        window.open('index.html', '_self');
    }
}

function ltrim(s) {
    var l = 0;
    while (l < s.length && s[l] == 0)
    { l++; }
    return s.substring(l, s.length);
}

function prepareForm(formName, SAPUserStore)
{
    //--añadir campos hidden
    formName.add({ xtype: 'hiddenfield', id: 'UserId', name: 'UserId', value: SAPUserStore.getAt(0).data.Uname });
    formName.add({ xtype: 'hiddenfield', id: 'PwdId', name: 'PwdId', value: SAPUserStore.getAt(0).data.Passwd });
    formName.add({ xtype: 'hiddenfield', id: 'Id', name: 'Id', value: SAPUserStore.getAt(0).data.Id });
}